package io.jpress.addon.interact.service.provider;

import com.jfinal.aop.Inject;
import com.jfinal.plugin.activerecord.Page;
import io.jboot.aop.annotation.Bean;
import io.jboot.db.model.Columns;
import io.jpress.addon.interact.service.JpressAddonInteractService;
import io.jpress.addon.interact.model.JpressAddonInteract;
import io.jboot.service.JbootServiceBase;
import io.jpress.model.User;
import io.jpress.service.UserService;

import java.util.List;

@Bean
public class JpressAddonInteractServiceProvider extends JbootServiceBase<JpressAddonInteract> implements JpressAddonInteractService {

    @Inject
    UserService userService;

    @Override
    public Page<JpressAddonInteract> paginate(int page, int pageSize) {

        Page<JpressAddonInteract> paginate = super.paginate(page, pageSize);
        List<JpressAddonInteract> list = paginate.getList();
        for(JpressAddonInteract j : list){
            User user = userService.findById(j.getUserId());
            j.setUser(user);
        }
        return paginate;
    }

    @Override
    public Page<JpressAddonInteract> paginateByColumns(int page, int pageSize, Columns columns) {

        Page<JpressAddonInteract> paginate = super.paginateByColumns(page, pageSize,columns);
        List<JpressAddonInteract> list = paginate.getList();
        for(JpressAddonInteract j : list){
            User user = userService.findById(j.getUserId());
            j.setUser(user);
        }

        return paginate;
    }

    @Override
    public Page<JpressAddonInteract> paginateByColumns(int page, int pageSize, Columns columns,String order) {

        Page<JpressAddonInteract> paginate = super.paginateByColumns(page, pageSize,columns,order);
        List<JpressAddonInteract> list = paginate.getList();
        for(JpressAddonInteract j : list){
            User user = userService.findById(j.getUserId());
            j.setUser(user);
        }

        return paginate;
    }
}
